package com.thinkersre.entity;


//import io.swagger.annotations.ApiOperation;

public class Page {
    //当前页码
    private int pageNo = 1;
    //显示上限
    private int pageSize = 10;
    //数据行总数(用于计算总页数)
    private int rowsTotal;
    //查询路径(用于复用分页链接
    private String path;

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        //当前页码判断是否异常
        if(pageNo >= 1){
        this.pageNo = pageNo;
        }
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        //确定页面显示条数
        if(pageSize >= 1 && pageSize <= 100){
        this.pageSize = pageSize;
        }
    }

    public int getRowsTotal() {
        return rowsTotal;
    }

    public void setRowsTotal(int rowsTotal) {

        if(rowsTotal >= 0){
            this.rowsTotal = rowsTotal;
        }
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

//    @ApiOperation("获取当前页的起始行")
    public int getOffset(){
        return (pageNo-1)*pageSize;
    }
//    @ApiOperation("获取总页数")
    public int getPageTotal(){
        if(rowsTotal % pageSize == 0){
            return rowsTotal/pageSize;
        }
        else {
            return rowsTotal/pageSize + 1;
        }
    }
//    @ApiOperation("获取起始页码")
    public int getFrom(){
        int from = pageNo - 2;
        return from > 1 ? from : 1;
    }
//    @ApiOperation("获取结束页码")
    public int getTo(){
        int to = pageNo + 2;
        int pageTotal = getPageTotal();
        return to > pageTotal ? pageTotal : to;

    }


}
